package com.maas.util.mybatis.jpa.littlenb.statement;

import com.littlenb.mybatisjpa.statement.AbstractStatementFactory;
import com.littlenb.mybatisjpa.statement.StatementFactory;
import com.littlenb.mybatisjpa.support.Constant;
import com.littlenb.mybatisjpa.type.SelectorStrategy;
//import  xxxx.LoggerUtil;
import com.maas.util.mybatis.jpa.littlenb.annotation.mapper.SelectDefinition;
import com.maas.util.mybatis.jpa.littlenb.annotation.mapper.SelectPageDefinition;
import com.maas.util.mybatis.jpa.littlenb.constant.ResultMapConstants;
import com.maas.util.mybatis.jpa.littlenb.meta.PersistentMeta;
import com.maas.util.mybatis.jpa.littlenb.statement.builder.SelectPageBuilder;
import com.maas.util.mybatis.jpa.littlenb.support.core.MyMybatisStatementAdapter;
import com.maas.util.mybatis.jpa.littlenb.support.template.select.SelectCertainSqlTemplate;
import com.maas.util.mybatis.jpa.littlenb.support.template.select.SelectIgnoreNullSqlTemplate;
import com.maas.util.mybatis.jpa.littlenb.support.template.select.SelectSqlTemplate;
import org.apache.ibatis.executor.keygen.NoKeyGenerator;
import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.mapping.SqlCommandType;
import org.apache.ibatis.mapping.SqlSource;
import org.apache.ibatis.mapping.StatementType;
import org.apache.ibatis.scripting.LanguageDriver;
import org.apache.ibatis.session.Configuration;

import java.lang.reflect.Method;

/**
 * @deprecated
 * 分页功能，未实现
 * @select 扫描器
 * 修改自 mybatis-jba
 * @author sway.li ->zxm
 */
public class SelectPageStatementFactory extends AbstractStatementFactory implements MyStatementBuildable {

  public static final StatementFactory INSTANCE = new SelectPageStatementFactory();
  MyMybatisStatementAdapter adapter;

  SelectPageBuilder builder = new SelectPageBuilder();

  /**
   * 返回MappedStatement 用于mybatis 的configuration.addMappedStatement(statement);
   * @param configuration
   * @param method
   * @param targetClass
   * @return
   */
  @Override
  public MappedStatement parseStatement(Configuration configuration, Method method,
      Class<?> targetClass) {
    return  null;
  }

  @Override
  public String buildSQL(PersistentMeta persistentMeta, Method method) {
    return builder.buildSQL(persistentMeta,method);
  }

  @Override
  public void parseStatement(MyMybatisStatementAdapter adapter, PersistentMeta persistentMeta, Method method) {
    this.adapter = adapter;
    builder.parseStatement( adapter,  persistentMeta,  method);
  }



  private SelectorStrategy recognizeStrategy(Method method) {
    SelectPageDefinition definition = method.getAnnotation(SelectPageDefinition.class);
    if (definition == null) {
      throw new RuntimeException(
          "'" + method.getName() + "' method is not annotation with 'SelectDefinition'.");
    }
    return definition.strategy();
  }



}
